package com.zlict.admin.controller;

import com.zlict.admin.domain.ProjectDevice;
import com.zlict.admin.service.IProjectDeviceService;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.core.page.TableDataInfo;
import com.zlict.common.enums.BusinessType;
import com.zlict.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目设备管理Controller
 * 
 * @author dzw
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/admin/device")
public class ProjectDeviceController extends BaseController
{
    @Autowired
    private IProjectDeviceService projectDeviceService;

    /**
     * 查询项目设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('admin:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectDevice projectDevice)
    {
        startPage();
        List<ProjectDevice> list = projectDeviceService.selectProjectDeviceList(projectDevice);
        return getDataTable(list);
    }

    /**
     * 导出项目设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('admin:device:export')")
    @Log(title = "项目设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectDevice projectDevice)
    {
        List<ProjectDevice> list = projectDeviceService.selectProjectDeviceList(projectDevice);
        ExcelUtil<ProjectDevice> util = new ExcelUtil<ProjectDevice>(ProjectDevice.class);
        util.exportExcel(response, list, "项目设备管理数据");
    }

    /**
     * 获取项目设备管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectDeviceService.selectProjectDeviceById(id));
    }

    /**
     * 新增项目设备管理
     */
    @PreAuthorize("@ss.hasPermi('admin:device:add')")
    @Log(title = "项目设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectDevice projectDevice)
    {
        return toAjax(projectDeviceService.insertProjectDevice(projectDevice));
    }

    /**
     * 修改项目设备管理
     */
    @PreAuthorize("@ss.hasPermi('admin:device:edit')")
    @Log(title = "项目设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectDevice projectDevice)
    {
        return toAjax(projectDeviceService.updateProjectDevice(projectDevice));
    }

    /**
     * 删除项目设备管理
     */
    @PreAuthorize("@ss.hasPermi('admin:device:remove')")
    @Log(title = "项目设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectDeviceService.deleteProjectDeviceByIds(ids));
    }
}
